<template>
  <div class="main_box" style="padding:10px;">
    <div class="add_wrap" style="    padding-left: 34px; padding-top: 16px;">
      <div class="tit">
        <h2>分 类 信 息</h2>
        <el-button type="success" size="small" plain icon="fa fa-mail-forward" @click="returnList" > 返 回</el-button>
      </div>
      <el-form :model="addForm" ref="addForm" label-width="200px" :rules="roleRules">
        <el-row>
          <el-form-item label="上级分类：">
            <span style="font-weight: bold;">{{addForm.parentName}}</span>
          </el-form-item>
          <el-form-item label="分类名称:" prop="classifyName" >
            <el-input v-model="addForm.classifyName" placeholder="请输入分类名称"></el-input>
          </el-form-item>
          <el-form-item label="分类类型:" prop="classifyType" >
            <el-input v-model="addForm.classifyType" placeholder="分类可为空" type="number"></el-input>
          </el-form-item>
          <!-- <el-form-item label="排序：" prop="sort" >
            <el-input v-model="addForm.sort"></el-input>
          </el-form-item> -->
          <el-form-item label="备注：" prop="remark" >
            <el-input v-model="addForm.remark" placeholder="请填写备注"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button plain type="primary" @click="sureClick()">保 存</el-button>
            <el-button @click="returnList">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
  import * as validators from "@/utils/validators";
  import * as message from "@/constants/message";
  import DocumentClassifyApi from "@/api/document/documentClassify";
  export default{
    data(){
      return {
        addForm:{
          classifyName:"",
          remark:"",
          sort:"",
          parentName:"",
          parentId: null ,
        },
        typeIds:[],
        roleRules: {
          classifyName: [
            { required: true, message: "请输入分类名称", trigger: "blur" }
          ]
        }
      }
    },
    mounted(){
      this.init();
      console.log(this.$route.query.name)
    },
    methods: {
      init(){
        this.addForm.parentId = this.$route.query.id;
        this.addForm.parentName = this.$route.query.name;
      },
      sureClick() {
        this.$refs.addForm.validate(valid => {
          if (valid) {
            this.addClassify();
          }
        })
      },
      addClassify() {
        let cond = {
          parentId: this.addForm.parentId,
          classifyType: this.addForm.classifyType,
          classifyName: this.addForm.classifyName,
          remark: this.addForm.remark,
          sort: this.addForm.sort
        };
        DocumentClassifyApi.AddClassify(cond)
          .then(data => {
            // console.log(data)
            this.$Utils.notifySuccess();
            this.returnList();
          });
      },
      returnList(){
        this.$store.dispatch('delView', this.$route);
        this.$router.push({path: '/document/documentClassifyManagement'});
      }
    },
  }
</script>
<style lang="scss" src="@/assets/css/views/add.scss" scope>
</style>
